<%@ page language="java" import="com.demo.util.Conn,java.sql.ResultSet" pageEncoding="UTF-8"%>
<%
String user_id = session.getAttribute("user_id").toString();
String application_date = request.getParameter("application_date");
String job_title = request.getParameter("job_title");
String job_starting_date = request.getParameter("job_starting_date");

String pageNum = request.getParameter("page");
pageNum = "".equals(pageNum) || pageNum == null ? "1" : pageNum;
int pageSize = 20;

String sql = " where app.company_id=" + user_id;
if (!"".equals(application_date) && application_date != null) 
	sql = sql + " and app.application_date ='" + application_date + "'";
if (!"".equals(job_title) && job_title != null) 
	sql = sql + " and j.job_title like '%" + job_title + "%'";
if (!"".equals(job_starting_date) && job_starting_date != null) 
	sql = sql + " and j.job_starting_date ='" + job_starting_date + "'";

String sqlCount = "select count(*) as cnt from dbf_application_info app" 
				+ " left join dbf_job_info j on app.job_id = j.job_id "
	  			+ " inner join dbf_stuuser st on st.stuuser_id = app.user_id " + sql;
sql = "select app.*,j.job_starting_date,j.job_title,st.name from dbf_application_info app "
	  + " left join dbf_job_info j on app.job_id = j.job_id "
	  + " inner join dbf_stuuser st on st.stuuser_id = app.user_id " + sql;
sql = sql + " limit " + (Integer.valueOf(pageNum).intValue() - 1) * 20 + "," + pageSize;

System.out.println(sql);
Conn conn = new Conn();
ResultSet rs = conn.find(sqlCount);
rs.next();
int count = rs.getInt("cnt");
rs.close();
rs = conn.find(sql);
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>applications</title>
	<link rel="stylesheet" type="text/css" href="../style.css">
  </head>
  
  <body>
  <table width="718" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td height="39" colspan="3" background="../images/main_title.jpg"><strong>&nbsp;&nbsp;&nbsp;&nbsp;<span class="menutitle">&nbsp;Recruitment Status</span></strong></td>
    </tr>
    <tr>
      <td valign="bottom"><img src="../images/menu_a.jpg" width="19" height="23"></td>
      <td valign="top">&nbsp;</td>
      <td valign="bottom"><img src="../images/menu_b.jpg" width="18" height="23"></td>
    </tr>
    <tr>
      <td width="19" valign="top" background="../images/menu_c.jpg"><img src="../images/menu_c.jpg" width="19" height="54"></td>
      <td width="681" valign="top"><form action="applications.jsp" method="post">
          <table border="0" cellspacing="0" cellpadding="0" style="width:100%">
            <tr>
              <td colspan="6" class="logintxt"><img src="../images/spacer.jpg" width="2" height="8"></td>
            </tr>
            <tr>
              <td width="8%" class="logintxt">Job Title:</td>
              <td width="21%" class="logintxt"><input name="job_title" type="text" class="logintxt" id="job_title" size="15"></td>
              <td width="15%" class="logintxt">Job Starting Date:</td>
              <td width="20%" class="logintxt"><input name="job_starting_date" type="text" class="logintxt" id="job_starting_date" size="15"></td>
              <td width="15%" class="logintxt">Application Date:</td>
              <td width="21%" class="logintxt"><input name="application_date" type="text" class="logintxt" id="application_date" size="15"></td>
            </tr>
            <tr>
              <td colspan="6">&nbsp;</td>
            </tr>
            <tr>
              <td colspan="6">
                <div align="center">
                  <input name="submit" type="image" src="../images/search_btn.jpg" value="search">              
                </div></td>
            </tr>
          </table>
          <br>
          <table width="100%" border="1" cellpadding="0" cellspacing="0" style="width:100%">
            <tr>
              <td colspan="5" class="logintxt" style="text-align:right"><%="1".equals(pageNum) ? "First" : "<a href=\"applications.jsp?page=1"
  							+ "&application_date=" + request.getParameter("application_date") == null ? "": request.getParameter("application_date")
  							+ "&job_title=" + request.getParameter("job_title") == null ? "": request.getParameter("job_title")
  							+ "&job_starting_date=" + request.getParameter("job_starting_date") == null ? "": request.getParameter("job_starting_date")
  							+ "\">First</a>" %>&nbsp;&nbsp; <%="1".equals(pageNum) ? "Previous" : "<a href=\"applications.jsp?page=" 
  							+ String.valueOf(Integer.valueOf(pageNum).intValue()  - 1) 
  							+ "&application_date=" + request.getParameter("application_date") == null ? "": request.getParameter("application_date")
  							+ "&job_title=" + request.getParameter("job_title") == null ? "": request.getParameter("job_title")
  							+ "&job_starting_date=" + request.getParameter("job_starting_date") == null ? "": request.getParameter("job_starting_date")
  							+ "\">Previous</a>" %>&nbsp;&nbsp; <%=((Integer.valueOf(pageNum).intValue() * pageSize)) < count ? "<a href=\"applications.jsp?page=" 
  							+ String.valueOf(Integer.valueOf(pageNum).intValue()  + 1) 
  							+ "&application_date=" + request.getParameter("application_date") == null ? "": request.getParameter("application_date")
  							+ "&job_title=" + request.getParameter("job_title") == null ? "": request.getParameter("job_title")
  							+ "&job_starting_date=" + request.getParameter("job_starting_date") == null ? "": request.getParameter("job_starting_date")
  							+ "\">Next</a>" : "Next" %>&nbsp;&nbsp; <%=((Integer.valueOf(pageNum).intValue()  * pageSize)) >= count ? "Last&nbsp;" : "<a href=\"applications.jsp?page=" 
  							+ (count % pageSize == 0 ? count / pageSize : count / pageSize + 1) 
  							+ "&application_date=" + request.getParameter("application_date") == null ? "": request.getParameter("application_date")
  							+ "&job_title=" + request.getParameter("job_title") == null ? "": request.getParameter("job_title")
  							+ "&job_starting_date=" + request.getParameter("job_starting_date") == null ? "": request.getParameter("job_starting_date")
  							+ "\">Last&nbsp;</a>" %> </td>
            </tr>
            <tr>
              <td colspan="5" height="5"></td>
            </tr>
            <tr>
              <th width="19%" class="style4" style="background-color:#FFC963">Applicant</th>
              <th width="27%" class="style4" style="background-color:#FFC963">Post</th>
              <th width="16%" class="style4" style="background-color:#FFC963">Post Date</th>
              <th width="13%" class="style4" style="background-color:#FFC963">Date</th>
              <th width="25%" class="style4" style="background-color:#FFC963">Remarks</th>
            </tr>
            <%
  						while(rs.next()) {
  					%>
            <tr>
              <td class="logintxt"><a href="stuResume.jsp?stuuser_id=<%=rs.getString("user_id")%>"><%=rs.getString("name") %></td>
              <td class="logintxt"><%=rs.getString("job_title") %></td>
              <td class="logintxt"><%=rs.getString("job_starting_date") %></td>
              <td class="logintxt"><%=rs.getString("application_date") %></td>
              <td class="logintxt"><%=rs.getString("remark") %></td>
            </tr>
            <%} %>
            <tr>
              <td colspan="5" height="20">&nbsp;</td>
            </tr>
        </table>
      </form></td>
      <td width="18" valign="top" background="../images/menu_d.jpg"><img src="../images/menu_d.jpg" width="18" height="54"></td>
    </tr>
    <tr>
      <td><img src="../images/menu_e.jpg" width="19" height="25"></td>
      <td background="../images/menu_f.jpg"><img src="../images/menu_f.jpg" width="181" height="25"></td>
      <td><img src="../images/menu_g.jpg" width="18" height="25"></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  </body>
</html>
